
Page({

  /**
   * 页面的初始数据
   */
  data: {
    zh: '',
    schema:[],
    formData:{
    },
    title: '',
    result: '',
    remark: '',
    webUrl: '',
    apiName: '',
    showPrivacy: false
  },
  onUnload() {
  },
  onLoad(options) {
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.title,
    })
    
    this.setData({
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
  },
  getFormData(e) {
    console.log('formdata==', e.detail.formData);
    this.setData({
      formData: e.detail.formData
    })
  },
  updateWeChatApp(e) {
    wx.updateWeChatApp({
      success: (res) => {
        this.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }, // 打开成功
      fail: (res) => {
        this.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      },
    })
  },
  getUpdateManager(e) {
    const updateManager = wx.getUpdateManager()
    this.setData({
      result: updateManager,
      apiName: e.currentTarget.dataset.apiname
    })
  },
  applyUpdate(e) {
    const that = this;
    const updateManager = wx.getUpdateManager()
    updateManager.onCheckForUpdate(function (res) {
      // 请求完新版本信息的回调
      if(that.data.zh === 'UpdateManager.onCheckForUpdate') {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      } else if(res.hasUpdate === false) {
        that.setData({
          result: '没有新版本',
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
    updateManager.onUpdateReady(function () {
      wx.showModal({
        title: '更新提示',
        content: '新版本已经准备好，是否重启应用？',
        success: function (res) {
          if (res.confirm) {
            // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
            updateManager.applyUpdate()
          }
        }
      })
    })
    updateManager.onUpdateFailed(function (res) {
      // 新版本下载失败
      if(that.data.zh === 'UpdateManager.onUpdateFailed') {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
  },
})